package top.sinno;

import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.ZipUtil;

import java.io.File;
import java.nio.charset.Charset;

public class RecursiveUnzip {
    final static File destDir = new File("D:\\Documents\\ziptest\\app1");
    public static void main(String[] args) {
                unzip(new File("D:\\Documents\\ziptest\\演示应用_20240606133950.zip"), Charset.forName("UTF-8") );
        zip("D:\\Documents\\ziptest\\演示应用_20240606133950","D:\\Documents\\ziptest\\演示应用_ddd1.zip", Charset.forName("UTF-8"));
    }

    public static void unzip(File zipFilePath, Charset charset) {
        System.out.println(zipFilePath.getAbsolutePath());
        if (zipFilePath.isDirectory()) {
            //如果是文件夹，则递归遍历
            for (File loopFile : FileUtil.loopFiles(zipFilePath)) {
                unzip(loopFile, charset);
            }
        } else {
            //如果是文件，则直接解压
            if (zipFilePath.exists() && (zipFilePath.getName().endsWith(".zip")||zipFilePath.getName().endsWith(".supp"))) {
                File unzip = ZipUtil.unzip(zipFilePath, charset);
                unzip(unzip, charset);
            }
        }
    }


    public static void zip(String zipFilePath,String targetFilePath, Charset charset) {
        String source="\\data\\lcdp\\source";
        File sourceSupp = ZipUtil.zip(zipFilePath+source,zipFilePath+source+".supp", charset,false);
        FileUtil.del(zipFilePath+source);

        String lcdp="\\data\\lcdp";
        File lcdpZip = ZipUtil.zip(zipFilePath+lcdp,zipFilePath+lcdp+".zip", charset,false);
        FileUtil.del(zipFilePath+lcdp);

        File appZip = ZipUtil.zip(zipFilePath,targetFilePath, charset,false);
        FileUtil.del(zipFilePath);

    }
}